package com.example.leetcode.niuke;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main2 {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String s1 = scanner.nextLine();
        String[] split = s.split(" ");
        List<Integer> collect = Arrays.stream(s1.split(" ")).map(Integer::parseInt).sorted().collect(Collectors.toList());
        if (collect.size() == 1) {
            System.out.println(-1);
            return;
        }
        int sum = 0;
        int differ = Integer.parseInt(split[1]);
        boolean[] booleans = new boolean[Integer.parseInt(split[0])];
        for (int i = 1;i<Integer.parseInt(split[0]);i++) {
            if(collect.get(i) - collect.get(i -1) <= differ) {
                if (!booleans[i] && !booleans[i -1]) {
                    sum += collect.get(i) - collect.get(i -1);
                    booleans[i] = true;
                    booleans[i -1] = true;
                }
            }
        }
        System.out.println(sum);
    }
}
